<template>
  <div>
    <a-modal
      title="安全关键会议分类"
      :visible="visible"
      :confirm-loading="loading"
      ok-text="保存"
      @ok="ok"
      @cancel="cancel"
    >
      <div class="about-master-container">
        <a-form-model ref="form" :model="queryParam" :rules="rules">
          <a-row>
            <a-col span="24">
              <a-form-model-item label="分类名称" prop="name">
                <BaseInput v-model="queryParam.name" placeholder="请输入" />
              </a-form-model-item>
            </a-col>
          </a-row>
          <a-row>
            <a-col span="24">
              <a-form-model-item label="状态" prop="enabled">
                <a-select v-model="queryParam.enabled">
                  <a-select-option value="TRUE">可用</a-select-option>
                  <a-select-option value="FALSE">不可用</a-select-option>
                </a-select>
              </a-form-model-item>
            </a-col>
          </a-row>
        </a-form-model>
      </div>
    </a-modal>
  </div>
</template>

<script>
import api from '@/api/safetySupervision/base/meetingType.js'

export default {
  name: 'a' + Date.now(),
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    form: {
      type: Object,
      default: () => null
    }
  },
  data() {
    return {
      loading: false,
      queryParam: { enabled: 'TRUE' },
      rules: {
        name: [{ required: true, message: '请输入分类名称', trigger: 'blur' }],
        enabled: [{ required: true, message: '请选择状态', trigger: 'blur' }]
      }
    }
  },
  watch: {
    visible(e) {
      if (e) {
        this.queryParam = this.form
      } else {
        this.queryParam = {}
        this.$refs.form.clearValidate()
      }
    }
  },
  methods: {
    async ok() {
      this.$refs.form.validate(async valid => {
        if (valid) {
          this.loading = true
          let res
          let temp = this.$clone(this.queryParam)
          // temp.type = 'MEETING_DEPT_TYPE'
          temp.type = 'SAFETY_KEY_MEETING'
          // temp.enabled = temp.enabled === 1
          // temp.enabled = (temp.enabled + '').toUpperCase()
          if (this.queryParam.id) {
            res = await api.edit({}, temp)
          } else {
            res = await api.add({}, temp)
          }
          this.loading = false
          if (res.code === this.SUCCESS_CODE) {
            this.$noticeSuccess('成功')
            this.$emit('ok', temp)
            this.cancel()
          }
        } else {
          this.$noticeWarning('请填写完整')
        }
      })
    },
    cancel() {
      this.$emit('update:visible', false)
    }
  }
}
</script>

<style lang="less" scoped>
</style>
